require 'observer'

class Employee
  include Observable

  attr_accessor :title, :salary, :name, :payroll_processor

  def initialize(name, title, salary)
    @title = title
    @name = name
    @salary = salary
  end

  def salary=(salary)
    @salary = salary
    changed()
    notify_observers(self)
  end
end

class PayrollProcessor
  def update(emp)
    puts("#{emp.name}'s salary has changed!")
  end
end

class TaxProcessor
  def update(emp)
    puts("#{emp.name}'s tax has changed!")
  end
end

def main()
  payroll_processor = PayrollProcessor.new()
  tax_processor = TaxProcessor.new()
  emp = Employee.new('sanjay', 'engineer', 23133)
  emp.add_observer(payroll_processor)
  tax_processor = TaxProcessor.new()
  emp.add_observer(tax_processor)
  emp.name = 'sasuke'
  emp.salary = 343
  emp.delete_observer(tax_processor)
  emp.salary = 3434
end

main()

